package com.wxq.dao.impl;

import com.wxq.bean.User;
import com.wxq.dao.BaseDao;
import com.wxq.dao.IUserDao;

/**
 * @ClassName UserDaoImpl
 * @Description: TODO
 * @Author Admin
 * @Date 2021/3/9
 * @Version V1.0
 **/
public class UserDaoImpl extends BaseDao implements IUserDao {
    @Override
    public boolean saveUser(User user) {
        int i = update("insert into user(username,password,email) values(?,?,?)", user.getUsername(), user.getPassword(), user.getEmail());
        if (i > 0) {
            return true;
        }
        return false;
    }

    @Override
    public User findUser(String name, String password) {
        User user = null;
        user = queryForOne(User.class, "select * from user where username=?", name);
        if (user == null) {
            user = new User();
            user.setMsg("用户名不存在");
            return user;
        }
        user = queryForOne(User.class, "select * from user where password=?", password);
        if (user == null) {
            user = new User();
            user.setMsg("密码错误");
            return user;
        }
        return user;
    }
}
